#pragma once

#include <iostream>
#include "Protocol.hpp"

class Cal
{
public:
    Response Calculate(Request& req)
    {
        int x = req.X(), y = req.Y();
        char op = req.Oper();
        int result = 0, exitcode = 0;
        switch(op)
        {
        case '+':
            result = x + y;
            break;
        case '-':
            result = x - y;
            break;
        case '/':
        {
            if(y == 0)
                exitcode = 1;   //除零错误
            else
                result = x / y;
            break;
        }
        case '%':
        {
            if(y == 0)
                exitcode = 2;   //模零错误
            else
                result = x % y;
            break;
        } 
        case '*':
            result = x * y;
            break;
        default:
            exitcode = 3;
            break;
        }
        return Response(result, exitcode);
    }

};